<table data-options="fit:true" id="fm_music"></table>
<script>
	$(function(){
		var datagrid;
		datagrid=$('#fm_music').datagrid({   
			url:"../json/BackFmMusicAction_findAllMusic",
    		loadMsg:'数据加载中...',
    		pagination:true,
		    fitColumns:true,
		    rownumbers:true,
		    striped:true,
		    pageNumber:1,
		    sortOrder:'asc',
		    remoteSort:false,//定义是否通过远程服务器对数据排序。
		    sortName:'mid',
    		columns:[[
    			{field:'mids',title:'',checkbox:true,width:100,align:'center'},      
		        {field:'mid',title:'编号',width:100,align:'center'},   
		        {field:'mname',title:'音乐名字',width:100,align:'center'},   
		        {field:'mtype',title:'类型',width:100,align:'center'},
		        {field:'mauthor',title:'作者',width:100,align:'center'},
		        {field:'mtime',title:'收录时间',width:100,align:'center'},
		        {field:'mnumber',title:'播放次数',width:100,align:'center'}, 
		        {field:'mdownload',title:'下载次数',width:100,align:'center'},           
    		]],
    		toolbar: [{
				iconCls: 'icon-add',
				text:'添加',
				handler: function(){
					$('#addFm_music').dialog("open");
				}
			},'-',{
				text:'删除',
				iconCls: 'icon-remove',
				handler: function(){
					//获取选中的行
					var rows=datagrid.datagrid("getChecked");
					if(rows.length==0){
						$.messager.alert('错误提示','请选择您要删除的文章...','error');
					}else{
						//获取到行中的id
						var mid="";
						//如果有多个
						if(rows.length>1){
							for(var i=0;i<rows.length-1;i++){
								mid+=rows[i].mid+",";
								alert(rows[i].mid);
							}
							mid+=rows[i].mid;
						}else{
							mid=rows[0].mid;
						}
						$.ajax({
							url:"../upload/BackFmMusicAction_delMusic",
							dataType:'json',
							type:"post",
							data:{
								"mid":mid
							},
							success:function(data){
								if(data.obj>0){
									$.messager.show({
										title:'成功提示',
										msg:'删除FM音频成功...',
										timeout:3000,
										showType:'slide'
									});
									datagrid.datagrid("reload");
								}else{
									$.messager.alert('错误提示','FM音频删除失败,请稍后重试...','error');
								}
							}
						});
					}
				}
			}] 
		}) 
	})
</script>

<div id="addFm_music" class="easyui-dialog" title="添加FM音频信息" style="width:800px;height:600px"
	data-options="iconCls:'icon-add',resizeble:true,modal:true,closed:true">
	<form action="" method="post" id="addFm_music_form" style="padding:30px;">
		<p><label>音乐名称:</label><input type="text" id="fmmusic_name" name="fname"></p>
		<p><label>音乐作者:</label><input type="text" id="fmmusic_author" name="fauthor"></p>
		<p><label>音乐类型:</label>
			<select id="fmmusic_type" name="ftype">
				<option>请选择类型</option>
				<option value="睡前">睡前</option>
				<option value="散步">散步</option>
				<option value="独处">独处</option>
				<option value="随便">随便</option>
				<option value="失眠">失眠</option>
				<option value="失恋">失恋</option>
			</select>
		</p>
		<p><span>音频地址:</span><input type="file" id="fmmusic_aAudio" name="file"/></p>
		
		<span>音频图片:</span><input type="file" id="fmmusic_aaddr" name="file" multiple="multiple"  onchange="previewMultipleImage(this,'show_pic')"/>
		<div id="show_pic">
			
		</div>
		<!-- 文章内容 -->
		<!--<div>
			<script type="text/plain" id="editor" style="width:800px;height:300px"></script>
		</div>
		-->
		<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="addFmMusic()">添加</a>
	</form>
</div>
<script>
	/*var ue=UE.getEditor('editor');*/
	
	function addFmMusic(){
		var mname=$("#fmmusic_name").val();
		var mauthor=$("#fmmusic_author").val();
		var mtype=$("#fmmusic_type").val();
		/*var mcontent=ue.getContent();*/
		console.info(mname+mauthor+mtype);
		$.ajaxFileUpload({
			url:"../upload/BackFmMusicAction_addFmMusicInfo",
			fileElementId:["fmmusic_aaddr"],
			secureuri:false,
			dataType:'json',
			type:"post",
			data:{
				mname:mname,
				mauthor:mauthor,
				mtype:mtype
			},
			success:function(data){
				console.info(data);
				if(data.obj>0 ){
					$.ajaxFileUpload({
						url:"../upload/BackFmMusicAction_updateMusic",
						fileElementId:["fmmusic_aAudio"],
						secureuri:false,
						dataType:'json',
						type:"post",
						data:{"mid":data.obj},
						success:function(data){
							if(data.obj>0){
								$.messager.show({
									title:'成功提示',
									msg:'FM音频添加成功...',
									timeout:3000,
									showType:'slide'
								});
								$('#addFm_music').dialog("close");
								$("#fmmusic_name").val("");
								$("#fmmusic_author").val("");
								$("#fmmusic_type").val("");
								$('#fm_music').datagrid("reload");
							}else{
								$.messager.alert('错误提示','FM音频添加失败,请稍后重试...','error');
							}
						}
					});
				}else{
					$.messager.alert('错误提示','FM音频添加失败,请稍后重试...','error');
				}
			}
		});
	}
</script>
